﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Taoyl.CodeTraceModels;

namespace Taoyl.CodeTraceDAL
{
    public class CodeRecordService
    {
        public int AddCodeRecord(CodeRecord record)
        {
            return SqlSugarHelper.SqlSugarClient.Insertable(record).ExecuteCommand();
        }

        public List<CodeRecord> QueryCodeRecords(DateTime start,DateTime end,string code,string result)
        {
            var quary=SqlSugarHelper.SqlSugarClient.Queryable<CodeRecord>().Where(c=>SqlFunc.Between(c.InsertTime,start,end)).OrderBy(c=>c.InsertTime);


            if (code.Length>0)
            {
                quary=quary.Where(c=>c.MotorCode.Contains(code));

            }

            if (result.Length > 0)
            {
                quary = quary.Where(c => c.MeasureResult==(result));

            }
            return quary.ToList();
        }
    }
}
